<!doctype html>
<html class="x-admin-sm" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
	<meta charset="UTF-8">
	<title>后台登录</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" th:href="@{/asserts/css/adminfont.css}">
    <link rel="stylesheet" th:href="@{/asserts/css/xadmin.css}">
    <link rel="stylesheet" th:href="@{/asserts/css/adminlogin.css}">
     <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet" />
     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
     <script th:src="@{/asserts/lib/layui/layui.js}" charset="utf-8"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
	 
   
</head>
<body class="login-bg">
    
    <div class="login layui-anim layui-anim-up">
        <div class="message">后台管理员登录</div>
        <div id="darkbannerwrap"></div>
        <form method="post" class="layui-form" >
            <input name="username" id="username" placeholder="用户名"  type="text" lay-verify="nikename" class="layui-input" >
            <hr class="hr15">
            <input name="password" id="password" lay-verify="pass" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">
            <input id="login" value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20" >
         </form>
    </div>
    <script type="text/javascript">
    $(function  () {
    	toastr.options = 
		{
	        positionClass: "toast-top-center",
	        closeButton: true,
	        timeOut:"1000",
	    };
        layui.use('form', function(){
          var form = layui.form;
          
          //检测是否符合规范
          form.verify({
              nikename: function(value) {
                  if (value.length < 5) {
                      return '昵称至少得5个字符';
                  }
              },
              pass: [/(.+){8,16}$/, '密码必须8到16位'],
          });
          
        //监听提交
          form.on('submit(login)', function(data){
        	  $.ajax({
  				type:"post",
  				url: "/admin/check",
  				data: JSON.stringify({username:$("#username").val(),password:$("#password").val()}),
  			    contentType: "application/json",
  			    dataType: "text",
  			    async: true,
  			    success: function (data) {
  			    	if(data=='正确')
  			    	{
  			    		console.log("管理员已启用");
  			    		toastr.success('登陆成功！1s后跳转');
  			    		setTimeout(function () {location.href="/admin/login";}, 1000);
  			    	}
  			    	else if(data=='用户名或密码不正确')
  			    	{
  			    		toastr.warning('用户名或密码不正确！');
  			    	}
  			    	else
  			    	{
  			    		toastr.warning('管理员未启用');
  			    	}
  			    },
  			    error: function (e) {
  			    	toastr.error('网络错误！')
  			    }	
  			});  
        	  return false;
            });
          
          
    });
    })
    </script>
    
</body>
</html>